<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>11-ajax-json</title>
    <script src="./myAjax2.js"></script>
    <script>
      window.onload = function () {
        var oBtn = document.querySelector("button");
        oBtn.onclick = function () {
          Ajax(
            "GET",
            "11-ajax-json.php",
            {},
            3000,
            function (xhr) {
              var str = xhr.responseText;
              //   把json格式转化为对象
              var obj = JSON.parse(str);
              console.log(obj);
              console.log(obj.name);
              console.log(obj.age);
            },
            function () {}
          );
        };
      };
    </script>
  </head>
  <body>
    <button>发送请求</button>
  </body>
</html>
